﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZLCMS.Data.Model;
using DotNet.Common.NHibernateUtil;
using NHibernate;
using ZLCMS.Web.Wap.Code;
using ZLCMS.Commands.Data;

namespace ZLCMS.Web.Wap.Shop
{
    public partial class CommentAppend : MemberPageBase
    {
        protected ProductData ProductData { get; set; }

        protected MemberComment Comment { get; set; }

        protected string OptionType { get; set; }

        protected string Title { get; set; }

        protected string CommandKey { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            OptionType = Request["type"];
            if (OptionType != "change" && OptionType != "append" && OptionType != "changeAll" && OptionType != "changecontent" && OptionType!="changeSC")
            {
                Response.Write("参数错误！");
                Response.End();
                return;
            }

            switch (OptionType)
            {
                case "change": Title = "修改评分"; CommandKey = "Member.ChangeCommentScore"; break;
                case "append": Title = "追加评论"; CommandKey = "Member.AppendComment"; break;
                case "changeAll": Title = "修改默认评论"; CommandKey = "Member.ChangeComment"; break;//修改所有
                case "changecontent": Title = "修改评论"; CommandKey = "Member.ChangeComment"; break;//修改评论内容
                case "changeSC": Title = "修改评论"; CommandKey = "Member.ChangeComment"; break;//修改分数和评论内容
                default: Title = "";
                    break;
            }

            using (ISession session = SessionFactoryHelper.CreateSession())
            {
                Comment = session.Get<MemberComment>(Int32.Parse(Request["comment"]));
                if (Comment == null || Comment.MemberAccount != CurrentMemberAccount)
                {
                    Response.Write("参数错误！");
                    Response.End();
                    return;
                }

                string sql = @"select op.product_no as ProductNo,op.product_name as ProductName,op.PRODUCT_IMAGE as ThumbnailImg,op.PRODUCT_SUMMARY as ShortDesc,
op.SALE_PRICE as SalePrice from shop_order_product op inner join shop_order_info o on o.ORDER_NO=op.ORDER_NO
where o.member_account=:member and op.product_no=:pno";
                ProductData = session.CreateSQLQuery(sql)
                    .SetParameter("member", CurrentMemberAccount)
                    .SetParameter("pno", Comment.TargetCode)
                    .SetResultTransformer(new ObjectResultTransformer(typeof(ProductData)))
                    .SetMaxResults(1)
                    .UniqueResult<ProductData>();

                if (ProductData == null)
                {
                    Response.Write("参数错误！");
                    Response.End();
                }
            }
        }
    }
}